# 描述一个任务
import time
from enum import Enum

from loguru import logger


class TaskStatus(Enum):
    EMPTY = 1
    BOILING = 2
    FOOD = 3
    WAIT_FOOD_READY = 4
    WAIT_FOR_TIMEOUT = 5
    WAIT_FOR_POUR_DONE = 6
    POUR_DONE = 7
    FINISH = 8


TASK_ID = 0
BOILED_TIMEOUT = 5  # 煮的时间


class Task:
    def __init__(self):
        # super().__init__()
        global TASK_ID
        self._status = None
        TASK_ID = TASK_ID + 1
        self._id = TASK_ID
        self._hole_index = None
        self._boiled_time = 0
        self._food_in_water = False  # 食物是否放在水中煮了
        self._pour_done = False  # 倒煮好食物的动作完成

        self.status = TaskStatus.EMPTY

    @property
    def status(self):
        # print("getter 被调用")
        return self._status

    @status.setter
    def status(self, status):
        logger.debug("任务{}状态设置为{}".format(self._id, status))
        if not isinstance(status, TaskStatus):
            raise TypeError("类型不匹配，应该为字符串型")
        self._status = status

    @property
    def id(self):
        return self._id

    @property
    def hole_index(self):
        return self._hole_index

    @hole_index.setter
    def hole_index(self, index):
        self._hole_index = index

    @property
    def boiled_time(self):
        return self._boiled_time

    @boiled_time.setter
    def boiled_time(self, time):
        self._boiled_time = time + BOILED_TIMEOUT

    def is_boiled_timeout(self):
        return time.time() > self._boiled_time

    def food_in_the_water(self):
        self._food_in_water = True

    def is_food_in_the_water(self):
        return self._food_in_water

    def set_pour_done(self, done=True):
        self._pour_done = done

    def is_pour_done(self):
        return self._pour_done
